document.addEventListener('DOMContentLoaded', function () {
    let musicPlaying = false;
    let currentVideoIndex = 0;
    let currentPhotoIndex = 0;
    // 视频列表
    let videos = [];
    let photos = []


    // 照片列表


    // 音频元素
    const backgroundMusic = document.getElementById('background-music');
    const applauseSound = document.getElementById('applause-sound');
    const musicToggle = document.getElementById('music-toggle');



    // 初始化
    init();

    function init() {
        // 启动粒子系统
        if (typeof initParticles === 'function') {
            initParticles();
        }
        addEventListeners();
        // 尝试自动播放音乐
        tryAutoPlayMusic();

    }

    function tryAutoPlayMusic() {
        const playPromise = backgroundMusic.play();
        if (playPromise !== undefined) {
            playPromise.then(() => {
                musicPlaying = true;
                musicToggle.textContent = '🎵';
                musicToggle.style.animation = 'musicPulse 2s infinite';
            }).catch(() => {
                musicPlaying = false;
                musicToggle.textContent = '🔇';

                // 添加用户交互启动音乐
                document.addEventListener('click', () => {
                    if (!musicPlaying) {
                        backgroundMusic.play().then(() => {
                            musicPlaying = true;
                            musicToggle.textContent = '🎵';
                            musicToggle.style.animation = 'musicPulse 2s infinite';
                        });
                    }
                }, {once: true});
            });
        }
    }

    function addEventListeners() {
        // 音乐控制
        musicToggle.addEventListener('click', toggleMusic);
    }

    function toggleMusic() {
        if (musicPlaying) {
            backgroundMusic.pause();
            musicToggle.textContent = '🔇';
            musicToggle.style.animation = 'none';
            musicPlaying = false;
        } else {
            backgroundMusic.play().then(() => {
                musicToggle.textContent = '🎵';
                musicToggle.style.animation = 'musicPulse 2s infinite';
                musicPlaying = true;
            }).catch(e => {
                console.log('音乐播放失败:', e);
            });
        }
    }

});

